
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const templateCache = require('gulp-angular-templatecache');

gulp.task('scss', () => {
  gulp.src(['app/styles/**/*.scss'])
    .pipe(sass({
      outputStyle: 'expanded'
    }).on('error', sass.logError))
    .pipe(autoprefixer())
    .pipe(gulp.dest('app/styles/'));
});

gulp.task('template', () => {
  return gulp.src(['app/templates/**/*.html'])
    .pipe(templateCache({
      module: 'xianwan'
    }))
    .pipe(gulp.dest('app/scripts/'));
});

gulp.task('default', () => {
  gulp.run('scss');
  gulp.run('template');
});

/**
 * 用于html在线热更新
 */
const connect = require("gulp-connect")//引入connect模块
const watch = require("gulp-watch")//引入watch模块
gulp.task("server",function(){
    connect.server({
        port:5050,
        livereload:true
    })
})
gulp.task("watch",function(){//监听文件的内容变换
    gulp.watch("app/templates/**/*.html",['template']);
    gulp.watch("app/styles/**/*.scss",['scss']);
})

gulp.task("serve",['server','watch'])